import 'package:flutter/material.dart';

class ExpansionPanelItem {
  final String headerText;
  final Widget body;
  bool isExpanded;

  ExpansionPanelItem({
    this.headerText,
    this.body,
    this.isExpanded
  });


}

class ExpansionPanelDemo extends StatefulWidget {
  ExpansionPanelDemo({Key key}) : super(key: key);

  @override
  _ExpansionPanelDemoState createState() => _ExpansionPanelDemoState();
}

class _ExpansionPanelDemoState extends State<ExpansionPanelDemo> {
  bool _isExpanded = false;
  List<ExpansionPanelItem> _expansionPanelItems;

  @override
  void initState() {
    super.initState();

    _expansionPanelItems = <ExpansionPanelItem>[
      ExpansionPanelItem(
        headerText: 'Pannel A',
        body: Container(
          padding: EdgeInsets.all(16.0),
          width: double.infinity,
          child: Text('Content for Panel A')
        ),
        isExpanded: false
      ),
      ExpansionPanelItem(
        headerText: 'Pannel B',
        body: Container(
          padding: EdgeInsets.all(16.0),
          width: double.infinity,
          child: Text('Content for Panel B')
        ),
        isExpanded: false
      ),
      ExpansionPanelItem(
        headerText: 'Pannel C',
        body: Container(
          padding: EdgeInsets.all(16.0),
          width: double.infinity,
          child: Text('Content for Panel C')
        ),
        isExpanded: false
      ),
    ];
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('ExpansionPanelDemo'),
        elevation: 0.0,
      ),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          ExpansionPanelList(
            expansionCallback: (int panelIndex, bool isExpander){
              setState(() {
                _expansionPanelItems[panelIndex].isExpanded = !isExpander;
              });
            },
            children: _expansionPanelItems.map((ExpansionPanelItem item){
              return ExpansionPanel(
                body: item.body,
                isExpanded: item.isExpanded,
                headerBuilder: (BuildContext context, bool isExpanded){
                  return Container(
                    padding: EdgeInsets.all(16.0),
                    child: Text(
                      item.headerText,
                      style: Theme.of(context).textTheme.headline6,
                    ),
                  );
                }
              );
            }).toList(),
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              
            ],
          )
        ],
      ),
    );
  }
}